#include <signal.h>
#include <stdio.h>
#include <unistd.h>
//按下CTRL-C时给出SIGINT信号，函数ouch将被调用，程序会在中断函数ouch结束后继续执行，退出则需按CTRL-\产生SIGQUIT信号
void ouch(int sig)
{
	printf("OUCH! - I got signal %d\n",sig);
	//(void) signal(SIGINT, SIG_DFL);
}
//截获按下CTRL-C组合键时产生的SIGINT信号
int main()
{
	struct sigaction act;
	act.sa_handler = ouch;
	sigemptyset(&act.sa_mask);//创建空白掩码
	act.sa_flags = 0;
	sigaction(SIGINT, &act, 0);

	//(void) signal(SIGINT,ouch);	
	
	while(1)
	{
		printf("hello world!\n");	
		sleep(1);
	}
}
